import edge_tts
import asyncio

def get_content(filename):
    content = ""
    with open(filename, "r", encoding="utf-8") as f:
        content = f.read()
    print(content)
    return content

async def gen_voice(filename):
    #edge-tts --list-voices
    voice = 'zh-CN-XiaoxiaoNeural'
    rate = '-10%'
    volume = '+0%'
    
    tts = edge_tts.Communicate(text=get_content(filename), voice=voice, rate=rate, volume=volume)

    await tts.save(filename.replace(".txt", ".mp3"))
    
if __name__ == '__main__':
    filename = 'abc.txt'
    asyncio.run(gen_voice(filename))